package com.yicong.ants.view;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Checkable;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.yicong.ants.R;

/**
 * 订单列表支付 PopupWindow
 */
public class OrderListPayPop extends BasePopupWindow {

    private TextView tvCheck;
    private ImageView ivCancel;
    private RelativeLayout reWeChat;
    private Checkable ckWeChat;
    private RelativeLayout reAliPay;
    private Checkable ckAliPay;
    private OrderListPayCall orderListPayCall;
    public OrderListPayPop(Context context) {
        super(context);
    }

    @Override
    public void initSetting() {
        this.setOutsideTouchable(true);
        this.setWidth(ViewGroup.LayoutParams.WRAP_CONTENT);
        this.setHeight(ViewGroup.LayoutParams.WRAP_CONTENT);
    }

    public void setOrderListPayCall(OrderListPayCall orderListPayCall) {
        this.orderListPayCall = orderListPayCall;
    }

    public void setAmount(String amount) {
        tvCheck.setText("确认支付￥" + amount);
    }

    @Override
    public void initListener() {
        super.initListener();
        ivCancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dismiss();
            }
        });
        reWeChat.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (ckWeChat.isChecked()) {
                    return;
                }
                ckWeChat.setChecked(true);
                ckAliPay.setChecked(false);
            }
        });
        reAliPay.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (ckAliPay.isChecked()) {
                    return;
                }
                ckAliPay.setChecked(true);
                ckWeChat.setChecked(false);
            }
        });
        tvCheck.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (null == orderListPayCall) {
                    return;
                }
                if (ckAliPay.isChecked()) {
                    orderListPayCall.callAliPay();
                } else {
                    orderListPayCall.callWeChat();
                }
                dismiss();
            }
        });
    }

    @Override
    public void initView() {
        mView = LayoutInflater.from(mContext).inflate(R.layout.popup_window_order_list_pay, null);
        ivCancel = mView.findViewById(R.id.iv_cancel);
        reWeChat = mView.findViewById(R.id.rel_wechat);
        ckWeChat = mView.findViewById(R.id.check_wechat);
        reAliPay = mView.findViewById(R.id.rel_alipay);
        ckAliPay = mView.findViewById(R.id.check_ali_pay);
        tvCheck = mView.findViewById(R.id.tv_pay);
    }

    public interface OrderListPayCall {
        void callAliPay();

        void callWeChat();
    }
}
